# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

#This uses CMake instead of meson because the CMake build
#generates *.cmake that are used by other libraries that
#depend upon CMake's findpackage function.

_realname=directx-headers
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.615.0
pkgrel=1
pkgdesc="Official DirectX headers available under an open source license (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: directx-headers'
)
url='https://github.com/microsoft/DirectX-Headers'
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/microsoft/DirectX-Headers/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('5394360b517f431949d751f3bcb4150313f28815aded514531c7aaea81bac314')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DDXHEADERS_BUILD_TEST=OFF \
      -DDXHEADERS_BUILD_GOOGLE_TEST=OFF \
      ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

  install -Dm644 "DirectX-Headers.pc" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/DirectX-Headers.pc"
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
